'use strict';
const BullQueue = require('bull');
const worker = require('./app/service/processor/worker.js');
const workerMulti = require('./app/service/processor/worker-multi.js');

class AppBootHook {
  constructor(app) {
    this.app = app;
  }


  async willReady() {
    this.app.regExp = new RegExp(this.app.config.erpRule.join('|'));
  }


  async serverDidReady() {

    this.app.queue = new BullQueue('tortious', { redis: this.app.config.bull });
    this.app.queue.process('tortious-worker', 1, async (job, done) => {
      return await worker(job, done, this.app);
    });

    this.app.multiQueue = new BullQueue('tortious-multi', { redis: this.app.config.bull });
    this.app.multiQueue.process('tortious-worker-multi', 1, async (job, done) => {
      return await workerMulti(job, done, this.app);
    });
  }
}
module.exports = AppBootHook;
